
#ifndef _MEMBER_BPIXMAP_H_
#define _MEMBER_BPIXMAP_H_

#include <BImage>
#include <BWidget>
#include <BMouseEvent>
#include <BPixmap>
#include <BDrag>
#include "IGLState.h"

#define pixmap_member(pixmap)		((member_BPixmap*)((BPixmap*)pixmap)->_ptr)

namespace BWE
{
	class member_BPixmap : public BObject
	{
		friend class BPixmap;
	public:
		member_BPixmap(BPixmap* pixmap);
		~member_BPixmap();

		bool check() const;

		void update(const BEvent& event);
		void fresh();
		void frame();

		void updateWidget(BWidget* widget, const BEvent& event);
		void freshWidget(BWidget* widget, const BEvent& event);

		bool hover(BWidget* widget);
		bool focus(BWidget* widget);
		bool popup(BWidget* widget, bool flag);

		BWidget* widgetUnderPoint(const BPoint& point);
		BWidget* findWidget(BWidget* widget, const BPoint& point, const BRect& clip);
		BWidget* findPopupWidget(BWidget* widget, const BPoint& point, const BRect& clip);

		void frameWidget(BWidget* widget);
		void drawWidget(BWidget* widget, const BRect& clip, const BPoint& offset, int frameHeight);
		void drawPopupWidget(BWidget* widget, const BRect& clip, const BPoint& offset, int frameHeight);
		void drawCursor(BPainter& painter);
		void drawDrag(BPainter& painter);
		void drawTips(BPainter& painter);
		void freshCursor();

		void procMousePress(BMouseEvent& mouseEvent);
		void procMouseRelease(BMouseEvent& mouseEvent);
		void procMouseMove(BMouseEvent& mouseEvent);
		void procMouseWheel(BMouseEvent& mouseEvent);
		void procDragMove(BMouseEvent& mouseEvent);
		void procDragDrop(BMouseEvent& mouseEvent);

		void slotImageDirty();
		void slotWidgetFramed();

	public:
		BPixmap*			boss;
		BSize				size;
		BColor				color;

		int					samples;
		bool				resized;
		IGLState			state;
		BUInt				fbo;
		BUInt				rbo;
		BUInt				msfbo;
		BUInt				msrbo;
		BUInt				mstbo;

	public:
		BWidgetHolderArray	widgets;
		BDrag*				drag;
		BCursorHolder		hoverCursor;
		BWidget*			hoverWidget;
		BWidget*			focusWidget;
		BWidgetArray		popupWidgets;

		BPoint				cursorPos;
		bool				refresh;
		bool				focusing;
		ITipsBoard			tipsBoard;

		BRect				currentRect;
		bool				mouse_pressed;
		BReal				mouse_pressed_time;
		BPoint				mouse_pressed_pos;
		BReal				mouse_click_time;
		BPoint				mouse_click_pos;
		BPoint				mouse_pos;
	};
}


#endif